package common.properties {
import common.properties.editors.TextPropertyViewer;
import common.properties.validation.PropertyValidator;

/**
 * Accumulator for all information about property:
 *   PropertyAccessor,
 *   PropertyEditor
 */
public class PropertyDescriptor {
    private var _name:String;
    private var _label:String;
    private var _accessor:PropertyAccessor;
    private var _editor:PropertyEditor;
    private var _viewer:PropertyViewer;
    private var _validator:PropertyValidator;
    private var _stage:String;

    public function get stage():String {
        return _stage;
    }

    public function get label():String {
        return _label;
    }

    public function get accessor():PropertyAccessor {
        return _accessor;
    }

    public function get editor():PropertyEditor {
        return _editor;
    }

    public function get viewer():PropertyViewer {
        return _viewer;
    }

    public function get validator():PropertyValidator {
        return _validator;
    }

    public function get name():String {
        return _name;
    }

    public function PropertyDescriptor(name:String, label:String, accessor:PropertyAccessor, editor:PropertyEditor, validator:PropertyValidator = null, viewer:PropertyViewer = null, stage:String = null) {
        _name = name;
        _label = label;
        _accessor = accessor;
        _editor = editor;
        _viewer = viewer == null ? new TextPropertyViewer() : viewer;
        _stage = stage;
        _validator = validator;

        if (_validator != null) {
            _validator.accessor = _accessor;
            _validator.listener = _editor.component;
        }
    }
}
}